<template>
    <div>
<!--        头部-->
        <topAdv :is-show="true"></topAdv>
<!--        主体-->
        <div id="outer">
            <div id="main">
                <el-tabs :tab-position="tabPosition">
                    <el-tab-pane label="我的主页">
                        <h2 id="myInformation">个人信息</h2>
                        <ul id="infoList">
                            <li class="contentsItem">
                                <span class="contentTitle" >昵称</span>
                                <a class="changeBtn" @click.prevent="centerDialogVisible_nickname = true">修改</a>
                                <el-dialog
                                        title="修改昵称"
                                        :visible.sync="centerDialogVisible_nickname"
                                        width="30%"
                                        center>
                                        <div>
                                            <input type="text" placeholder="请输入您的新昵称" class="personalChange" v-model="changeNickname">
                                        </div>
                                        <span slot="footer" class="dialog-footer">
                                            <el-button @click="centerDialogVisible_nickname = false">取 消</el-button>
                                            <el-button type="primary" @click="nicknameChange">确 定</el-button>
                                        </span>
                                </el-dialog>
                                <p class="showContent">{{$store.state.userInfo.nickname}}</p>
                            </li>
                            <li class="contentsItem">
                                <span class="contentTitle">手机号</span>
                                <a @click.prevent="centerDialogVisible_phone = true" class="changeBtn">修改</a>
                                <el-dialog
                                        title="修改手机号"
                                        :visible.sync="centerDialogVisible_phone"
                                        width="30%"
                                        center>
                                    <div style="text-align: left">
                                        <input type="text" class="personalChange" placeholder="请输入您的新手机号" v-model="changePhone">
                                        <input type="text" class="personalChange" placeholder="请输入验证码" v-model="changePhoneCode">
                                        <button @click="getCodeChangePhone" ref="getCodeThi">获取验证码</button>
                                    </div>
                                        <span slot="footer" class="dialog-footer">
                                            <el-button @click="centerDialogVisible_phone = false">取消</el-button>
                                            <el-button type="primary" @click="phoneChanging">修改</el-button>
                                        </span>
                                </el-dialog>
                                <p class="showContent">{{$store.state.userInfo.mobile}}</p>
                            </li>
                            <li class="contentsItem">
                                <span class="contentTitle">密码</span>
                                <a @click.prevent="centerDialogVisible_pwssword = true" class="changeBtn">修改</a>
                                <el-dialog
                                        title="修改密码"
                                        :visible.sync="centerDialogVisible_pwssword"
                                        width="30%"
                                        center>
                                    <div>
                                        <input type="password"  class="personalChange" placeholder="请输入您的旧密码" v-model="oldPwd">
                                        <input type="password"  class="personalChange" placeholder="请输入您的新密码" v-model="newPwd">
                                        <input type="password"  class="personalChange" placeholder="请再次输入新密码" v-model="confirmPwd">
                                        <input type="text"  class="personalChange" placeholder="请输入您的手机号" v-model="confirmPhone">
                                        <input type="text"  class="personalChange" placeholder="请输入您的验证码" v-model="confirmCode">
                                        <button @click="sendCode" ref="getCodeFourth">获取验证码</button>
                                    </div>
                                        <span slot="footer" class="dialog-footer">
                                            <el-button @click="centerDialogVisible_pwssword = false">取 消</el-button>
                                            <el-button type="primary" @click="changeMyPwd">确 定</el-button>
                                        </span>
                                </el-dialog>
                                <p class="showContent">******</p>
                            </li>
                            <li class="contentsItem">
                                <div id="headPhotoBox">
                                    <img :src="$store.state.userInfo.avatarUrl" alt="">
                                </div>
                                <el-upload
                                        class="upload-demo"
                                        action="/api/pcUser/updata/userAvatar"
                                        multiple
                                        :limit="3"
                                        :on-success="changeHeadPhoto">
                                    <el-button size="small" type="primary"><i class="el-icon-upload el-icon--right"></i>更改头像</el-button>
                                </el-upload>
                            </li>
                        </ul>
                    </el-tab-pane>
                    <el-tab-pane label="我的课程">
                        <el-tabs v-model="activeName">
                            <el-tab-pane label="正在学习" name="first">
                                <ul id="learning">
                                    <li>
                                        <div class="imgBox"></div>
                                        <h5 class="courseTitle">我是课程名字</h5>
                                        <h5 class="courseNum">共节课<span></span> | <span></span>人报名</h5>
<!--                                        <h4 class="freeLogo" v-if="item.isFree==1">免费</h4>-->
<!--                                        <p class="coursePrice" v-if="item.isFree==0">-->
<!--                                            <span v-if="item.isDiscount==1">&yen;{{item.discountPrice}}<span class="originalPrice">&nbsp;&yen;{{item.coursePrice}}</span></span>-->
<!--                                            <span v-if="item.isDiscount==0"><span class="price">&yen;{{item.coursePrice}}</span></span>-->
<!--                                            <span class="preferential" v-if="item.isDiscount==1">{{item.discountDesc}}</span>-->
<!--                                        </p>-->
                                    </li>
                                </ul>
                            </el-tab-pane>
                            <el-tab-pane label="我的收藏" name="second">我的收藏</el-tab-pane>
                            <el-tab-pane label="我的报名" name="third">我的报名</el-tab-pane>
                            <el-tab-pane label="观看记录" name="fourth">观看记录</el-tab-pane>
                        </el-tabs>
                    </el-tab-pane>
                    <el-tab-pane label="我的订单">
                        <el-tabs v-model="activeName">
                            <el-tab-pane label="用户管理" name="first">全部订单</el-tab-pane>
                            <el-tab-pane label="配置管理" name="second">等待付款</el-tab-pane>
                            <el-tab-pane label="角色管理" name="third">付款成功</el-tab-pane>
                        </el-tabs>
                    </el-tab-pane>
                </el-tabs>
            </div>
        </div>
<!--        底部-->
        <footNav></footNav>
    </div>
</template>

<script>
    import topAdv from "../../components/topAdv";
    import footNav from "../../components/footNav";
    import {
        changeNickname,
        changePhoneGetCode,
        phoneChanging,
        sendCode, toChangePwd
    } from "../../../api/personalCenter";
    import {exitLogin} from "../../../api/topAdv";
    import buttonTiming from "../../../api/common";

    export default {
        name: "information",
        data(){
            return {
                tabPosition: 'left',
                activeName: 'first',
                centerDialogVisible_nickname: false,
                centerDialogVisible_phone: false,
                centerDialogVisible_pwssword: false,
                changeNickname:"",
                changePhone:"",
                changePhoneCode:"",
                changePwd:'',
                    oldPwd:"",
                    newPwd:'',
                    confirmPwd:'',
                    confirmPhone:'',
                    confirmCode:''

            }
        },
        methods:{
            //修改昵称
            nicknameChange(){
                changeNickname(this.changeNickname).then(res=>{
                    if(res.code==0){
                        this.$store.commit("modifyUserinfo",res.userInfo);
                    }
                })
                this.centerDialogVisible_nickname = false;
            },
            //修改手机号时获取验证码
            getCodeChangePhone(){
                changePhoneGetCode(this.changePhone).then(res=>{
                    if(res.code==0){
                        alert("发送成功，注意查收！");
                        buttonTiming(this.$refs.getCodeThi);
                    }else{
                        alert("发送失败，请检查手机号是否正确！")
                    }
                })
            },
            //修改手机获取验证码后点击修改
            phoneChanging(){
                phoneChanging(this.changePhone,this.changePhoneCode).then(res=>{
                    this.$store.commit("modifyUserinfo",res.userInfo)
                })
                this.centerDialogVisible_phone = false;
            },
            //头像上传成功后更新用户信息
            changeHeadPhoto(file){
                this.$store.commit("modifyUserinfo",file.userInfo)
            },
            //个人中心修改密码是发送验证码
            sendCode(){
                sendCode(this.confirmPhone).then(res=>{
                    if(res.code==0){
                        buttonTiming(this.$refs.getCodeFourth);
                        alert("发送成功，注意查收！")
                    }else{
                        alert("发送失败，请检查手机号是否正确！")
                    }
                })
            },
            //个人中心修改密码
            changeMyPwd(){
                toChangePwd(this.oldPwd,this.newPwd,this.confirmPwd,this.confirmPhone,this.confirmCode).then(res=>{
                    if(res.code==0){
                        exitLogin().then(res=>{
                            if(res.code==0){
                                this.$store.state.isLogin = false;
                                this.$router.push({path:'/index'});
                                alert("请使用新密码重新登陆")
                            }
                        })
                    }
                })
                this.centerDialogVisible_pwssword = false;
            }


        },
        components:{
            topAdv,
            footNav
        }
    }
</script>

<style scoped lang="less">
    #infoList{
        height: 100% !important;
    }
//主题颜色
@hoverColor:#00cf8c;
//主体外部大盒子
    #outer{
        width: 100%;
        background-color: #f4f4f4;
        padding-top: 20px;
        padding-bottom: 20px;
    }
/*    主体内部居中的盒子*/
    #main{
        margin:auto;
        padding-top: 20px;
        width: 1200px;
        background-color: white;
    }
    /*修改滚动条颜色*/
    /deep/
    .el-tabs__active-bar{
        background-color: @hoverColor;
    }
/*    修改鼠标移入样式*/
    /deep/
        .el-tabs__item:hover{
        color: @hoverColor;
    }
    /deep/
        .el-tabs__item.is-active{
        color: @hoverColor;
    }
/*    三个导航之前的间距*/
    /deep/
    .el-tabs__item{
        height: 50px;
        line-height: 50px;
        text-indent: 2em;
    }
/*    我的主页*/
    .el-tab-pane{
        padding-left: 15px;
    }
    /*个人信息*/
    #myInformation{
        margin-top: 10px;
        font-size: 22px;
        font-weight: normal;
        text-align: left;
    }
    /*个人信息中的每项内容*/
    .contentsItem{
        margin: 30px auto 0px;
        height: 90px;
        width: 970px;
        text-align: left;
        border-bottom: 1px solid lightgray;
        display: inline-block;
    }
    .contentsItem:first-child{
        margin-top: 50px;
    }
    .contentsItem:last-child{
        border-bottom: 0px;
    }
    #headPhotoBox{
        img{
            width: 200px;
        }
    }
/*    昵称、手机号、密码title的样式*/
    .contentTitle{
        font-size: 20px;
    }
    .changeBtn{
        margin-left: 10px;
        color: @hoverColor;
        cursor: pointer;
    }
    .showContent{
        margin-top: 10px;
        font-size: 20px;
        color: #333;
        line-height: 40px
    }
    .el-button--primary{
        color: black;
        background-color: white;
    }
    .el-button--primary:hover{
        background-color: white;
        color: black;
    }
/*    正在学习*/
    #learning{
        overflow: hidden;
        li{
            float: left;
            width: 182px;
            text-align: left;
        }
        .imgBox{
            height:100px;
            background-color: yellow;
        }
    }
    .courseNum{
        margin: 0;
        margin-top: 5px;
        color: #888;
        font-weight: normal;
    }
    .courseTitle{
        margin: 0;
        margin-top: 3px;
        font-weight: 500;
        color: black;
    }
/*    免费标志*/
.freeLogo{
    margin-top: 10px;
    color: @hoverColor;
    font-weight: normal;
}
.coursePrice{
    margin-top: 10px;
    float: left;
    width: 220px;
    color: #ff4500;
    font-size: 16px;
    line-height: 22px;
}
.originalPrice{
    color: #999;
    text-decoration: line-through;
    font-size: 12px;
    line-height: 22px;
}
.preferential{
    margin-right: 10px;
    float: right;
    width: 64px;
    height: 22px;
    color: #fa8c16;
    background: #fff7e6;
    border: 1px solid #ffd591;
    box-sizing: border-box;
    border-radius: 2px;
    text-align: center;
    line-height: 22px;
    font-size: 12px;
}
    .personalChange{
        width: 400px;
        height: 30px;
    }
</style>